package com.ba.base.view

import android.view.View
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import qsos.lib.netservice.data.HttpStatusEnum
import qsos.lib.netservice.data.IHttpStatusCode

abstract class AbsHttpStateFragment : AbsThemeFragment() {

    abstract fun getHttpState(): MutableLiveData<IHttpStatusCode>


    override fun initView(view: View) {
        super.initView(view)

        getHttpState().value = HttpStatusEnum.SUCCESS
        getHttpState().observe(this, Observer {
            when (it.statusCode) {
                200 -> loadSuccess()
                401 -> showLoginout()
                else -> {
                    showError(it.statusMsg)
                    loadError(it)
                }
            }
        })
    }

    abstract fun loadSuccess()
    abstract fun loadError(status: IHttpStatusCode)

}